function varargout = cell_tracker(varargin)
% CELL_TRACKER M-file for cell_tracker.fig
%      CELL_TRACKER, by itself, creates a new CELL_TRACKER or raises the existing
%      singleton*.
%
%      H = CELL_TRACKER returns the handle to a new CELL_TRACKER or the handle to
%      the existing singleton*.
%
%      CELL_TRACKER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CELL_TRACKER.M with the given input arguments.
%
%      CELL_TRACKER('Property','Value',...) creates a new CELL_TRACKER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before cell_tracker_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to cell_tracker_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help cell_tracker

% Last Modified by GUIDE v2.5 07-Jan-2013 16:21:38

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @cell_tracker_OpeningFcn, ...
                   'gui_OutputFcn',  @cell_tracker_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before cell_tracker is made visible.
function cell_tracker_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to cell_tracker (see VARARGIN)

% Choose default command line output for cell_tracker
handles.output = hObject;
handles.phasedir=[];
handles.fluordir=[];
handles.maskdir=[];
handles.outdir=[];
handles.basedir=[];

%matlabpool
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes cell_tracker wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = cell_tracker_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.phasedir = [uigetdir(handles.basedir) filesep];
set(handles.text1,'String',handles.phasedir)
handles.basedir=handles.phasedir;
guidata(hObject, handles);


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.maskdir = [uigetdir(handles.basedir) filesep];
set(handles.text2,'String',handles.maskdir)
handles.basedir=handles.maskdir;
guidata(hObject, handles);


function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function parameters=getParameters(handles)

parameters.subexperiment=get(handles.edit1,'String');
parameters.numcolors=str2double(get(handles.edit2,'String'));
parameters.step=str2double(get(handles.edit3,'String'));
parameters.binSize=str2double(get(handles.edit4,'String'));
parameters.numOfPreviousFramesToConsider=str2double(get(handles.edit6,'String'));
%change parameters.maskConcat to ask for user input if desired
parameters.maskConcat='mask_';
%Setup Trajectory Navigator
parameters.TN.frame=1;
parameters.TN.object=2;
parameters.TN.score=3;
parameters.TN.TBC1=4;
parameters.TN.TBC2=5;

%Setup Object Navigator
ON.Area=1;
ON.CentroidX=2;
ON.CentroidY=3;
ON.Eccentricity=4;
ON.Orientation=5;
ON.Number=6;
numOfFields=length(fieldnames(ON));
for k=1:parameters.numcolors
    ON.fluorMean(k)=numOfFields+k;
    ON.fluorStd(k)=numOfFields+parameters.numcolors+k;
    ON.fluorMax(k)=numOfFields+2*parameters.numcolors+k;
    ON.fluorPrcRatio(k)=numOfFields+3*parameters.numcolors+k;
end
parameters.ON=ON;

parameters.CP.trajNumber=1;
parameters.CP.score=2;
parameters.CP.active=3;

parameters.maskfilenames=getFilenameCellList(handles.maskdir,'*.tif');
phasepattern = ['*' parameters.subexperiment 'c1.tif'];
parameters.phasefilenames=getFilenameCellList(handles.phasedir,phasepattern);
parameters.maskfilenamesToOutput=getFilenameCellListConcat(handles.phasedir,phasepattern,handles.maskdir,parameters.maskConcat);

for cn = 1:parameters.numcolors
   %come up with the color pattern, note the colors begin at c2 to
   fluorpattern=['*' parameters.subexperiment 'c' num2str(cn+1) '.tif'];
   parameters.fluorfilenames(cn,:)=getFilenameCellList(handles.fluordir,fluorpattern);
   %set(get(handles.listbox1,'String'),'c'
end

%find image dimensions from the mask
mask=imread(parameters.maskfilenames{1});
parameters.imageDimensions(1)=size(mask,2);
parameters.imageDimensions(2)=size(mask,1);

parameters.binnedDimensions=round(parameters.imageDimensions/parameters.binSize);

parameters.AvCellBox=21;
%weighting parameters for Will's Metric
parameters.alpha=0.5;
parameters.beta=2;
parameters.epsilon=1;
parameters.gamma=0.25;

parameters.prcRange=[10 90];




% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

blankflag=get(handles.checkbox8,'Value');

%colorOutputFlag.trajRGB=get(handles.checkbox10,'Value');
%colorOutputFlag.overlay=get(handles.checkbox11,'Value');

if(get(handles.checkbox7,'Value'))
    if(isfield(handles,'velocityfield'))
        velocityfield=handles.velocityfield;
    end
else
    velocityfield=[];
end

handles.parameters=getParameters(handles);

%run ObtainObjects function
[handles.ObjectsByFrame] =  ObtainObjects(handles.parameters,blankflag);

%make trajectories
[handles.Traj, handles.TrajInFrames] = makeTrajectoriesFromBinnedObjects(...
    handles.ObjectsByFrame,velocityfield,handles.parameters);

  updateTrajTable(handles)


'finished making trajectories'
guidata(hObject, handles);

function updateTrajTable(handles)
%Create a table giving the length of found trajectories
tableString{1,1}='Number of total trajectories';
tableString{1,2}=num2str(length(handles.Traj));
l=zeros(length(handles.Traj),1);
for i=1:length(handles.Traj)
    [l(i) temp]=size(handles.Traj{i});
end
tableString{2,1}='Number of trajectories > 10';
tableString{2,2}=num2str(sum(l>10));
tableString{3,1}='Number of trajectories > 25';
tableString{3,2}=num2str(sum(l>25));
tableString{4,1}='Number of trajectories > 50';
tableString{4,2}=num2str(sum(l>50));
tableString{5,1}='Number of trajectories > 75';
tableString{5,2}=num2str(sum(l>75));
tableString{6,1}='Number of trajectories > 100';
tableString{6,2}=num2str(sum(l>100));
tableString{7,1}='Number of trajectories > 150';
tableString{7,2}=num2str(sum(l>150));
tableString{8,1}='Number of trajectories > 200';
tableString{8,2}=num2str(sum(l>200));
columnformat={'char','char'};
set(handles.uitable1,'ColumnFormat',columnformat,'Data',tableString);

hist(handles.axes1,l(l>10));
%set(handles.axes1,'YScale','log');
xlabel('Trajectory size')
ylabel('Counts')
title('Histogram of trajectory sizes')




% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.outdir = [uigetdir(handles.basedir) filesep];
set(handles.text7,'String',handles.outdir)
handles.basedir=handles.outdir;
guidata(hObject, handles);





% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.outTrajPropFile=get(handles.edit7,'String');

handles.propsToOutput.Frame=get(handles.checkbox15,'Value');
handles.propsToOutput.Area=get(handles.checkbox1,'Value');
handles.propsToOutput.Centroid=get(handles.checkbox2,'Value');
handles.propsToOutput.Eccentricity=get(handles.checkbox3,'Value');
handles.propsToOutput.Orientation=get(handles.checkbox4,'Value');
handles.propsToOutput.fluorMean=get(handles.checkbox5,'Value');
handles.propsToOutput.fluorStd=get(handles.checkbox6,'Value');
handles.propsToOutput.c2c3ratio=get(handles.checkbox9,'Value');
handles.propsToOutput.fluorMax=get(handles.checkbox13,'Value');
handles.propsToOutput.fluorPrcRatio=get(handles.checkbox14,'Value');
handles.propsToOutput.fluorMaxC3=get(handles.checkbox16,'Value');

handles.lengthOfTrajToSave=str2double(get(handles.edit9,'String'));

selectedButton=get(handles.uipanel5,'SelectedObject');
if(selectedButton==handles.radiobutton1)
    handles.propsToOutput.shifted=0;
    handles.propsToOutput.unshifted=1;
elseif(selectedButton==handles.radiobutton2)
    handles.propsToOutput.shifted=1;
    handles.propsToOutput.unshifted=0;
end
    
WriteTrajectories_c3max(handles.Traj,handles.ObjectsByFrame,handles.outTrajPropFile,...
    handles.outdir,handles.parameters,handles.lengthOfTrajToSave,handles.propsToOutput)

guidata(hObject, handles);




% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.outMatFile=get(handles.edit8,'String');

%[handles.outdir handles.outMatFile]
Traj=handles.Traj;
ObjectsByFrame=handles.ObjectsByFrame;
TrajInFrames=handles.TrajInFrames;
parameters=handles.parameters;
%TrajBin=handles.TrajBin;
save([handles.outdir handles.outMatFile],'Traj','ObjectsByFrame','TrajInFrames','parameters')
'wrote .mat file'

guidata(hObject, handles);




% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if(handles.outdir)
    if(isdir(handles.outdir))
        outMatPIVvelocityFile=get(handles.edit10,'String');
        subexperiment=get(handles.edit1,'String');
        
        phasepattern = ['*' subexperiment 'c1.tif'];
        phasefilenames=getFilenameCellList(handles.phasedir,phasepattern);
%         phasepattern = ['*' handles.subexperiment 'c1.tif'];
%         phasefilelist = dir([handles.phasedir phasepattern]);
%         
%         
%         for j=1:length(phasefilelist)
%             phasefilelist(j).path=[handles.phasedir phasefilelist(j).name];
%         end       
%         phasefilenames = {phasefilelist.path}';
        
        %[handles.velocityfield]=cellTrackerMatPIV(handles.imagedir,phasefilenames);
        %velocityfield=handles.velocityfield;
        [velocityfield]=cellTrackerMatPIV(phasefilenames);
        
        save([handles.outdir outMatPIVvelocityFile],'velocityfield')
        
        'wrote MatPIV velocity .mat file'
        
    else
        'please enter a valid output directory before running MatPIV'
    end
else
    'please enter a valid output directory before running MatPIV'
end

% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)





% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[velocityFieldFile velocityfieldPath]= uigetfile;
pathToFile=[velocityfieldPath velocityFieldFile];
loadedVariables = load(pathToFile);
if(isfield(loadedVariables,'velocityfield'))
    handles.velocityfield=loadedVariables.velocityfield;
    set(handles.text14,'String',['Loaded velocityfield from file: ' velocityFieldFile]);
    guidata(hObject, handles);
else
    'please load a .mat file with a valid MatPIV velocityfield'
end

    

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% handles.output = hObject;
% handles.Objects=varargin{1}{1};
% handles.Traj=varargin{1}{2};
% %handles.TrajBin=varargin{1}{3};
% handles.TrajInFrames=varargin{1}{3};
% handles.velocityfield=varargin{1}{4};
% 
% %handles.maskdir = varargin{1}{5};
% handles.parameters = varargin{1}{5};

varargin{1}=handles.ObjectsByFrame;
varargin{2}=handles.Traj;
varargin{3}=handles.TrajInFrames;
varargin{4}=handles.velocityfield;
varargin{5}=handles.parameters;

% phasepattern = ['*' handles.subexperiment 'c1.tif'];
% phasefilelist = dir([handles.phasedir phasepattern]);
% 
% for j=1:length(phasefilelist)
%     phasefilelist(j).path=[handles.phasedir phasefilelist(j).name];
% end
% 
% phasefilenames = {phasefilelist.path}';
% 
% varargin{6}=phasefilenames;
% %varargin{6}=handles.imagedir;
% %varargin{7}=phasefilenames;


TrajViewer(varargin)


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.fluordir = [uigetdir(handles.basedir) filesep];
set(handles.text15,'String',handles.fluordir)
handles.basedir=handles.fluordir;
guidata(hObject, handles);

% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file dir]= uigetfile;

loadedVariables=load([dir file]);

handles.Traj=loadedVariables.Traj;
handles.ObjectsByFrame=loadedVariables.ObjectsByFrame;
handles.TrajInFrames=loadedVariables.TrajInFrames;
handles.parameters=loadedVariables.parameters;
'loaded .mat file'
guidata(hObject, handles);

% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
colorOutputFlag.trajRGB=get(handles.checkbox10,'Value');
colorOutputFlag.overlay=get(handles.checkbox11,'Value');
colorOutputFlag.overlayFluor=get(handles.checkbox12,'Value');

%write trajectory output file
if(colorOutputFlag.trajRGB || colorOutputFlag.overlay || colorOutputFlag.overlayFluor)
    WriteColoredTrajectoryImages(handles.ObjectsByFrame,handles.Traj,...
        handles.TrajInFrames,handles.parameters,handles.outdir,colorOutputFlag)
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   LOCATION FOR UNUSED CALLBACKS AND CREATE FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox8


% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox9


% --- Executes on button press in checkbox10.
function checkbox10_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox10


% --- Executes on button press in checkbox11.
function checkbox11_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox11
function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox7

% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox1


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox2


% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox3


% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox4


% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox5


% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox6



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% % --- Executes on button press in pushbutton12.
% function pushbutton12_Callback(hObject, eventdata, handles)
% % hObject    handle to pushbutton12 (see GCBO)
% % eventdata  reserved - to be defined in a future version of MATLAB
% % handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in checkbox12.
function checkbox12_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox12


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in checkbox13.
function checkbox13_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox13


% --- Executes on button press in checkbox14.
function checkbox14_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox14


% --- Executes on button press in checkbox15.
function checkbox15_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox15


% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.parameters=getParameters(handles);
%use the following two variables for the input and output file names of the
%mask create function
%parameters.phasefilenames;
%parameters.maskfilenamesToOutput;

guidata(hObject, handles);

function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes during object creation, after setting all properties.
function pushbutton14_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in checkbox16.
function checkbox16_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox16
